package com.guava;

public class ObjectDemo {
	public static void main(String[] args) {
		Object obj = new Object();
		Thread thread = new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					synchronized (obj) {
						System.out.println("第1 子线程wait");
						obj.wait();
					}
					System.out.println("第1 子线程继续执行");
				} catch (InterruptedException e) {
					System.out.println("11111111111");
					e.printStackTrace();
				}
			}
		});
		thread.start();
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					synchronized (obj) {
						System.out.println("第2 子线程wait");
						obj.wait();
					}
					System.out.println("第2 子线程继续执行");
				} catch (InterruptedException e) {
					System.out.println("11111111111");
					e.printStackTrace();
				}
			}
		}) .start();
		
		new Thread(new Runnable() {
			@Override
			public void run() {
				synchronized (obj) {
					try {
						Thread.sleep(5000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println("第3 子线程notify");
					System.out.println("---------------------------------------");
					obj.notifyAll();
				}
				System.out.println("第3 子线程继续执行");
			}
		}) .start();
		
//		try {
//			thread.join();
//		} catch (InterruptedException e) {
//			System.out.println("22222222");
//			e.printStackTrace();
//		}
		try {
			synchronized (obj) {
				System.out.println("主线程wait");
				obj.wait();
			}
			System.out.println("主线程继续执行");
		} catch (InterruptedException e) {
			System.out.println("333333333");
			e.printStackTrace();
		}
		System.out.println("主线程结束");
	}

}
